import { axios } from "@/utils/request";

const api = {
  user: "/user",
  role: "/role",
  service: "/service",
  permission: "/permission",
  permissionNoPager: "/permission/no-pager",
  orgTree: "/org/tree"
};

export default api;

export function getUserList(parameter) {
  return axios({
    url: api.user,
    method: "get",
    params: parameter
  });
}

export function getRoleList(parameter) {
  return axios({
    url: api.role,
    method: "get",
    params: parameter
  });
}

export function getServiceList(parameter) {
  return axios({
    url: api.service,
    method: "get",
    params: parameter
  });
}

export function getPermissions(parameter) {
  return axios({
    url: api.permissionNoPager,
    method: "get",
    params: parameter
  });
}

export function getOrgTree(parameter) {
  return axios({
    url: api.orgTree,
    method: "get",
    params: parameter
  });
}

// id == 0 add     post
// id != 0 update  put
export function saveService(parameter) {
  return axios({
    url: api.service,
    method: parameter.id === 0 ? "post" : "put",
    data: parameter
  });
}

//post
export function postAction(url, parameter) {
  return axios({
    url: url,
    method: 'post',
    data: parameter
  })
}

//get
export function getAction(url, parameter) {
  return axios({
    url: url,
    method: 'get',
    params: parameter
  })
}

/**
* 下载数据
*/
export function exportAction(url, parameter) {
  return axios({
      url: url,
      method: "get",
      params: parameter,
      responseType: 'blob'
  });
}

export function exportPostAction(url, parameter) {
  return axios({
    url: url,
    method: 'post',
    data: parameter,
    responseType: 'blob'
  })
}
